// pages/me/index.js
Page({
  /**
   * 页面的初始数据
   */
  data: {
    grades: [],
    courses: [],
    value1: 0,
    value2: 0,
    videoList:[],
  },
  onShareAppMessage() {},

  onShareTimeline() {},
  onLoad() {
    const that = this
    wx.cloud.callFunction({
      name: 'grade',
      data: {
        type: 'findAll',
      }
    }).then(res => {
      const grades = res.result.data;
      grades.forEach(m => {
        m.value = m.grade_no
        m.text = m.grade_name
      })
      grades.unshift({text:'请选择年级',value:0})
      that.setData({
        grades
      })
    })
    wx.cloud.callFunction({
      name: 'course',
      data: {
        type: 'findAll',
      }
    }).then(res => {
      const courses = res.result.data;
      courses.forEach(m => {
        m.value = m.course_no
        m.text = m.course_name
      })
      courses.unshift({text:'请选择学科',value:0})
      that.setData({
        courses
      })
    })
  },
  getLogin() {

  },
  onSwitch1Change({ detail }) {
    this.setData({
      value1:detail
    })
  },

  onSwitch2Change({ detail }) {
    const query = {"grade_no":this.data.value1,"course_no":detail}
    const that = this
    wx.cloud.callFunction({
      name: 'video',
      data: {
        type: 'query',
        query: query
      }
    }).then(res=>{
      that.setData({
        videoList:res.result.data
      })
    })
  },

  seeOne(event) {
    wx.navigateTo({
      url: '/pages/video/index?video_url=' + event.target.dataset.video.video_url+' & video_name='+event.target.dataset.video.video_name
    })
  },
});